﻿using UnityEngine;
using System.Collections;

public class RoamingSawOfDoom : MonoBehaviour  {
    public Transform Target, Vis;
    public float Speed = 15.0f;

    Transform Trnsfrm;
    float Cur;
    
    void Awake() {
        Trnsfrm = transform;  
    }
	void Update () {

        var vec = Target.position - Trnsfrm.position; var mag = vec.magnitude;
        Cur += Time.deltaTime *Speed / mag;
        var m = Cur;
        if(m >1.0f ) {
            if( m > 2.0f) 
                Cur = m -= 2.0f;
            else 
                m = 2.0f -m;
        }
         
        m = (m-0.5f)*2.0f;  
        m = Mathf.Sign(m)-m;
        m*= Mathf.Abs(m); 
        m = Mathf.Sign(m)-m;
        m = m*0.5f +0.5f;
        
        Vis.position = Trnsfrm.position + vec *m;
	}

}
